﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace Ezhu.WPFWin
{
    public partial class GetSetXML : Form
    {
        public GetSetXML()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 写入XML
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SetXML_Click(object sender, EventArgs e)
        {
            try
            {
                int readByte = 0;
                int bytesToRead = 100;
                string fileName = "text.xml";
                //打开图片文件，利用该图片构建一个文件流
                FileStream fs = new FileStream("Image/controls-01.png", FileMode.Open);
                //使用文件流构造二进制读取器将基元数据读作二进制值
                BinaryReader br = new BinaryReader(fs);
                //打开xml文件用utf8格式进行编写准备
                XmlTextWriter xmlTxtWt = new XmlTextWriter(fileName, Encoding.UTF8);
                //缩进格式
                xmlTxtWt.Formatting = Formatting.Indented;

                xmlTxtWt.WriteStartDocument();  //xml1.0版本声明
                xmlTxtWt.WriteStartElement("picture", "ContactDetails", "http:43.254.2.77");
            }
            catch (Exception)
            {
                
                throw;
            }
        }
        private byte[] a = null;
        private void GetXML_Click(object sender, EventArgs e)
        {
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load("text.xml");
            XmlNode xn = xmldoc.SelectSingleNode("data");
        }

        

        //byte[] 转图片    
        public static Bitmap BytesToBitmap(byte[] Bytes)
        {
            MemoryStream stream = null;
            try
            {
                stream = new MemoryStream(Bytes);
                return new Bitmap((Image)new Bitmap(stream));
            }
            catch (ArgumentNullException ex)
            {
                throw ex;
            }
            catch (ArgumentException ex)
            {
                throw ex;
            }
            finally
            {
                stream.Close();
            }
        }


    }
}
